{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#ssh -N -f -L localhost:8899:localhost:8899 gehongfei@114.213.253.204\n",
    "#http://localhost:8899\n",
    "#data_path=\"/Data/gehongfei/river\"\n",
    "import os\n",
    "from PIL import Image\n",
    "import copy\n",
    "import numpy as np\n",
    "data_path=\"/home/gehongfei/data/river/\"\n",
    "image_h=720\n",
    "image_w=1280"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "txt_path=os.path.join(data_path,\"11.txt\")\n",
    "with open(txt_path, \"r\") as f:  # 打开文件\n",
    "    data = f.read()  # 读取文件\n",
    "rgb_list=data.split(\",\")\n",
    "tempt=[]\n",
    "for i in rgb_list:\n",
    "    tempt.append(int(i))\n",
    "len(tempt)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "j=[]\n",
    "k=[]\n",
    "for i in range(len(tempt)):\n",
    "    j.append(tempt[i])\n",
    "    if (i+1)%3==0:\n",
    "        k.append(j)\n",
    "        j=[]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "aa=np.array(k)\n",
    "aa.mean(axis=0)\n",
    "np.sqrt(aa.var(axis=0))\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1003.jpg', '1047.jpg', '1080.jpg', '1042.jpg', '1011.jpg', '1028.jpg', '1095.jpg', '1067.jpg', '1013.jpg', '1031.jpg', '1010.jpg', '1012.jpg', '1056.jpg', '1055.jpg', '1032.jpg', '1096.jpg', '25.jpg', '1021.jpg', '1014.jpg', '1075.jpg', '1064.jpg', '1097.jpg', '1000.jpg', '1006.jpg', '1029.jpg', '1085.jpg', '1088.jpg', '1069.jpg', '1057.jpg', '1098.jpg', '1033.jpg', '1053.jpg', '1030.jpg', '1035.jpg', '1066.jpg', '1059.jpg', '1062.jpg', '1048.jpg', '1061.jpg', '1001.jpg', '1094.jpg', '1009.jpg', '1050.jpg', '1018.jpg', '1037.jpg', '1044.jpg', '1041.jpg', '1023.jpg', '1.jpg', '37.jpg', '1015.jpg', '1039.jpg', '1090.jpg', '43.jpg', '1092.jpg', '1036.jpg', '1072.jpg', '1017.jpg', '1052.jpg', '1005.jpg', '1082.jpg', '1089.jpg', '1022.jpg', '1065.jpg', '1016.jpg', '1038.jpg', '1073.jpg', '1046.jpg', '1099.jpg', '1060.jpg', '1063.jpg', '1043.jpg', '1083.jpg', '1040.jpg', '1071.jpg', '1086.jpg', '17.jpg', '1020.jpg', '1074.jpg', '1058.jpg', '1045.jpg', '1084.jpg', '1004.jpg', '1091.jpg', '1034.jpg', '1002.jpg', '1079.jpg', '1077.jpg', '1027.jpg', '1024.jpg', '1026.jpg', '1087.jpg', '1100.jpg', '1019.jpg', '1007.jpg', '1008.jpg', '1093.jpg', '1068.jpg', '1025.jpg', '21.jpg', '1049.jpg', '1051.jpg', '1054.jpg', '1078.jpg', '1081.jpg', '1076.jpg', '1070.jpg']\n"
     ]
    }
   ],
   "source": [
    "def get_image_list():\n",
    "    image_list=[]\n",
    "    for file in os.listdir(data_path):\n",
    "        a=os.path.splitext(file)\n",
    "        if a[1]==\".jpg\":\n",
    "            image_list.append(file)\n",
    "    return image_list\n",
    "image_list=get_image_list()\n",
    "print(image_list)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "def filter(a):\n",
    "    if (a[0]>179 and a[0]<227) and (a[1]>0 and a[1]<65) and (a[2]>0 and a[2]<69):\n",
    "        return True\n",
    "    else:\n",
    "        return False\n",
    "\n",
    "def get_sum(a):\n",
    "    bb=[]\n",
    "    for i in (a):\n",
    "        num=0\n",
    "        for j in i:\n",
    "            #print(j)\n",
    "            if filter(j):\n",
    "                num=num+1\n",
    "        bb.append(num)\n",
    "    return bb\n",
    "\n",
    "def get_index_row(image_name):\n",
    "    image_path=os.path.join(data_path,image_name)\n",
    "    image=Image.open(image_path)\n",
    "    array_image=np.array(image)\n",
    "    input_list=get_sum(array_image)\n",
    "    rank = [index for index, value in sorted(list(enumerate(input_list)), key=lambda x:x[1])]\n",
    "    rank_max=rank[-4:]\n",
    "    #print(rank_max)\n",
    "    rank_max.sort()\n",
    "    #print(rank_max)\n",
    "    print(\"图片：%s，红色边框在上下边分别在%d行和%d行。\"%(image_name,rank_max[0],rank_max[-1]))\n",
    "\n",
    "def get_index_col(image_name):\n",
    "    image_path=os.path.join(data_path,image_name)\n",
    "    image=Image.open(image_path)\n",
    "    array_image=np.array(image)\n",
    "    array_image=array_image.transpose(1,0,2)\n",
    "    input_list=get_sum(array_image)\n",
    "    rank = [index for index, value in sorted(list(enumerate(input_list)), key=lambda x:x[1])]\n",
    "    rank_max=rank[-4:]\n",
    "    #print(rank_max)\n",
    "    rank_max.sort()\n",
    "    #print(rank_max)\n",
    "    print(\"图片：%s，红色边框在左右边分别在%d列和%d列。\"%(image_name,rank_max[0],rank_max[-1]))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "a=1"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}